<template>
    <div class="e-form">
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="formData" label-width="160px" :rules="rules">

                <el-row>
                    <el-col :span="12">
                        <el-form-item label="结算编号：">
                           <el-input v-model="formData.settleNo" :disabled="isDisabled" >
                                {{formData.settleNo }}
                           </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                            <el-input v-model="formData.orgName" :disabled="true">
                                <span>{{ formData.orgName }}</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="业务类型" prop="businessTypeValue">
                            <el-select
                                v-model="formData.businessTypeKey"
                                placeholder="请选择"
                                 @change="busTypeChange"
                            >
                                  <el-option
                                  v-for="(
                                    item
                                    ) in businessDtlLists"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                    >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="源单编号：" prop="sourceNo">
                            <el-input v-model="formData.sourceNo " :disabled="true">
                                <span>{{formData.sourceNo }}</span>
                            </el-input>

                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="结算单位">
                            <el-input placeholder="请选择结算单位" v-model="formData.settleOrg" class="input-with-select" :disabled="true">
                                <!-- <el-button slot="append" @click="settleOrgChange" >选择结算明细</el-button> -->
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="结算类型：" prop="settleType">
                           <el-input v-model="formData.settleType" :disabled="true">
                                <span>{{formData.settleType }}</span>
                           </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="发票号" prop="invoiceNo">
                            <el-input v-model="formData.invoiceNo">
                                 <span>{{formData.invoiceNo }}</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="录入人员：">
                            <el-input :disabled='true' v-model='formData.inputName'>
                                <span>{{formData.inputName}}</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="不含税金额(元)" >
                            <el-input v-model="formData.taxExcluding"
                             @change="e =>{
                                amountExcludingTaxHandel(e)
                                }"
                            >
                            <span>
                                {{formData.taxExcluding}}
                            </span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="结算日期：" v-model="formData.settleDate">
                            <el-date-picker
                                v-model="formData.settleDate"
                                type="date"
                                placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="税率" prop="taxRate" >
                             <el-input v-model="formData.taxRate" placeholder="展示为%"
                             @change="e =>{taxRateHandel(e)}"
                             >
                                <span>{{formData.taxRate}}</span>
                           </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="税价合计：">
                           <el-input v-model="formData.totalTaxPrice" :disabled="true">
                                <span>{{formData.totalTaxPrice}}</span>
                           </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="税额：" >
                            <el-input placeholder="业务类型对应的源单带入" class="input-with-select" v-model="formData.taxAmount"
                            @change="e =>{
                                contractAmount(e)
                                }"
                            >
                              <span>
                                    {{formData.taxAmount}}
                              </span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="累计结算金额：">
                           <el-input v-model="formData.cumulativeSettleAmount" :disabled="true"
                            @change='e =>{
                                exchangeRateChange(e)
                            }'>
                                <span>{{ formData.cumulativeSettleAmount }}</span>
                           </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="服务单位费用(含税，元)：" >
                            <el-input placeholder="" v-model="formData.transportUnitCost" class="input-with-select"
                            @change="e =>{transportUnitCostHandel(e)}"
                            :disabled="true"
                            >
                                <span>
                                    {{formData.transportUnitCost}}
                                </span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="单据来源：" prop="billSource">
                            <el-input v-model="formData.billSource">
                                <span>{{ formData.billSource }}</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲预付款金额(元)：" >
                              <el-checkbox v-model="checkedBox" @change='changeHandel'>
                                   <el-input placeholder="" v-model="formData.advanceChargeAmount" class="input-with-select"
                                    @input="e =>{advanceChargeAmountHandel(e)}" :disabled="checkedBox ? false :true"
                                   />
                              </el-checkbox>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="验收编号：">
                            <el-input v-model="formData.acceptanceNo">
                               <span>{{ formData.acceptanceNo }}</span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲个人借支：">
                            <el-checkbox @change="checkHandel" :checked="checkPerson" :disabled="formData.businessTypeKey != '1'"></el-checkbox>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="终期结算：">
                            <el-checkbox v-model="setFinalSettle" @change="checkToF"></el-checkbox>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲个人借支金额(元)：" >
                            <el-input placeholder=""  v-model="formData.rushPersonalBorrowingAmount" class="input-with-select"
                            :disabled="checkPerson?false:true" @change="personHandel"
                            >
                                <span>
                                    {{formData.rushPersonalBorrowingAmount}}
                                </span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="币种：">
                                <el-select
                                v-model="formData.currency"
                                placeholder="请选择"
                                @change="currencyChange"
                            >
                                <el-option
                                    v-for="(
                                        item
                                    ) in currencyForm"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="冲销对象：">
                             <el-input placeholder="请输入内容" class="input-with-select" v-model="formData.reversalObjectName" :disabled="true">
                                <el-button slot="append" @click='handelChange' :disabled="checkPerson?false:true">选择</el-button>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="状态：" >
                            {{shuziShow(formData.state)}}
                            <!-- <el-input placeholder="" v-model="formData.state" class="input-with-select" disabled="true" >
                               <template slot-scope="{ row }">
                                    {{shuziShow(row.state)}}
                                </template>
                            </el-input> -->
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="借支人员：" >
                            <el-input placeholder="" class="input-with-select"  v-model="formData.borrower" :disabled="checkPerson?false:true" >
                                  <el-button slot="append" @click='getSigningName' :disabled="checkPerson?false:true">选择</el-button>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="备注：" >
                            <el-input placeholder="" v-model="formData.remarks" class="input-with-select" type="textarea"
                            :rows="3">
                            <span>
                                {{formData.remarks}}
                            </span>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="12">
                        <!-- 仅发生冲红单业务时,才显示该字段,暂未做判断 -->
                        <el-form-item label="冲红单:">
                            <div :style="redBillStateStyle">{{ redBillStateFun(formData.redStatus) }}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="传输财务共享：">
                            <span :class="isFontColor ? 'redFont' : 'greenFont'">{{shareLable(formData.transferFinancialShare)}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                v-debounce
                >保存</el-button
            >
            <el-button size="small" @click="handleClose"  v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/PCCset/apply.js'
import { getRmbRate } from '@/api/equip/common.js'
import { mapState } from 'vuex'
import { selectDataClient,  formatDate } from '@/utils/common'
// import { selectDataClient,  formatDate } from '@/utils/common'
// import NewPlanBillingDetails from './NewPlanBillingDetails.vue'
export default {
    data () {
        return {
            redBillStateStyle: {},
            setFinalSettle: false,
            checkPerson: false,
            optionssettleOrg: [{         //冲销对象
                valuesettleOrg: '1',
                label: '结算单位',
            }, {
                valuesettleOrg: '2',
                label: '服务服务单位'
            }],
            valuesettleOrg: '',
            businessDtlLists: [{         //业务类型
                value: '1',
                label: '临时需用计划',
            }, {
                value: '2',
                label: '物资采购合同'
            }, {
                value: '3',
                label: '调拨单'
            }],
            // businessDtlLists: ['临时需用计划', '物资采购合同', '调拨单'],
            value: '',
            checkedBox: false,
            dataList: {},
            value1: '',
            serviceFeeId: [],
            formData: {
                'acceptanceNo': '',
                'advanceChargeAmount': 0,
                'baseCurAmount': 0,
                'baseCurId': '',
                'baseCurName': '',
                'baseCurRate': 0,
                'billId': '',
                'billNo': '',
                'billSource': 0,
                'borrower': '',
                'businessTypeKey': 0,
                'businessTypeValue': '',
                'cumulativeSettleAmount': 0,
                'currency': '',
                'currencyId': '',
                'evaluationGrade': 0,
                'inputId': '',
                'inputName': '',
                'invoiceNo': '',
                'isFinalSettle': 0,
                'isRed': 0,
                'isRushAdvanceCharge': 0,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDesciption': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'parentId': '',
                'redStatus': 0,
                'remarks': '',
                'reversalObjectId': 0,
                'reversalObjectName': 0,
                'rmbAmount': 0,
                'rmbRate': 0,
                'rushPersonalBorrowing': 0,
                'rushPersonalBorrowingAmount': 0,
                'settleDate': formatDate(new Date(), 'yyyy-MM-dd'), //结算日期,
                'settleOrg': '',
                'settleOrgId': '',
                'settleType': 0,
                'sourceId': '',
                'sourceNo': '',
                'state': 0,
                'taxAmount': 0,
                'taxExcluding': 0,
                'taxRate': 0,
                'totalTaxPrice': 0,
                'transferFinancialShare': 0,
                'transportUnitCost': 0,
                'workId': '',
                'settleAmount': 0
            },
            rules: {
                advanceChargeAmount: [
                    { required: true, message: '请填写冲预付款金额为必填项', trigger: 'change' }
                ],
                settleNo: [
                    { required: true, message: '请填写结算编号', trigger: 'blur' }
                ],
                orgName: [
                    { required: true, message: '请填写机构名称', trigger: 'blur' }
                ],
                businessTypeKey: [
                    { required: true, message: '请选择业务类型', trigger: 'change' }
                ],
                settleDate: [
                    { required: true, message: '请选择结算日期', trigger: 'blur' }
                ],
                settleOrg: [
                    { required: true, message: '请选择冲销对象', trigger: 'change' }
                ],
                taxRate: [
                    { required: true, message: '请填写税率，可填范围0~100', trigger: 'blur' }
                ],
                billSource: [
                    { required: true, message: '请填写单据来源', trigger: 'blur' }
                ],
                invoiceNo: [
                    { required: true, message: '请填写发票号', trigger: 'blur' }
                ],
                remarks: [
                    { max: 500, message: '长度不超过500个字符', trigger: 'blur' }
                ],
            },
            isDisabled: false,
            test: '',
            isFontColor: true, //传输财务共享颜色  未传，返回修改 红色   财务共享审核中，已传 绿色

        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
            leaseTypeList: state => state.equip.equipData.leaseTypeList, //租赁类型
        }),
        //传输财务共享
        shareLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.shareFrom
                const obj = state.find(x=>x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
        // totalTaxPrice () {
        //     return this.formData.cumulativeSettleAmount + this.formData.taxAmount
        // }
    },
    created () {
        // const date = new Date()
        // this.formData.settleDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
        this.formData.inputName = localStorage.getItem('userName')
        this.getInInfo ()
        this.billid = this.$route.query.billid
        const { baseCyByOrgId } = this.userInfo
        this.formData.baseCurName = baseCyByOrgId.currencyName  //本位币
        this.formData.baseCurName = baseCyByOrgId.currency
        this.formData.orgId = this.userInfo.orgInfo.orgId
    },
    components: {
        // NewPlanBillingDetails
    },
    mounted () {
    },
    methods: {
        //选择业务类型
        busTypeChange () {
            console.log(this.formData.businessTypeKey)
            const findObj = this.businessDtlLists.find(item => item.value === this.formData.businessTypeKey)
            console.log(findObj)
            this.formData.businessTypeValue = findObj.label
            this.formData.sourceNo = ''
            this.formData.sourceId = ''
            this.formData.currency = ''
            this.formData.currencyId = ''
            this.formData.settleOrg = ''
            this.formData.settleOrgId = ''
            this.formData.taxRate = ''
        },
        //选择物资时补全基本信息内容
        async assignmentFun (data) {
            this.formData.settleOrg = data.settleOrgName // 结算单位
            this.formData.settleOrgId = data.settleOrgId // 结算单位ID
            // this.formData.purchaserName = data.purchasingPersonnelName // 采购人员名称
            this.formData.inputId = data.purchasingPersonnelId // 录入人员ID
            this.formData.sourceNo = data.billNo // 源单编号
            this.formData.sourceId = data.billId // 源单ID
            // 如果选择的是零星采购计划，物资采购合同，调拨单这三种,需要调接口获取币种,本位币,如果是物资采购合同：还需要带入合同税率
            if (
                this.formData.businessTypeKey == 1 ||
                this.formData.businessTypeKey == 3
            ) {
                let res1 = await request.getCurrency(data.billId)
                if (res1) {
                    this.formData.currency = res1.currency // 币种名称
                    this.formData.currencyId = res1.currencyId // 币种ID
                    this.formData.baseCurName = res1.baseCurName // 本位币名称
                    this.formData.baseCurId = res1.baseCurId // 本位币ID
                }
            }
            // // 如果选择的是物资采购合同,调合同的接口带入税率
            if (this.formData.businessTypeKey == 2) {
                let data1 = await request.getcontractbasicInfo(data.sourceId)
                console.log(data1, 'data111111')
                if (data1) {
                    this.formData.currency = data1.currencyName // 币种名称
                    this.formData.currencyId = data1.currencyId // 币种ID
                    this.formData.baseCurName = data1.baseCurName // 本位币名称
                    this.formData.baseCurId = data1.baseCurId // 本位币ID
                    this.formData.taxRate = data1.taxRate // 物资采购合同：带入合同税率。
                }
            }
        },
        changeHandel () {},
        //状态红单
        redBillStateFun (redStatus) {
            if(redStatus == 1) {
                return '冲销中'
            }else if(redStatus == 2) {
                return '已冲销'
            }else if(redStatus == 3) {
                return '红单'
            }else if(redStatus == -1) {
                return '未冲销'
            }
        },
        //状态数字转换
        shuziShow (state) {
            if(state == -1) {
                return '已删除'
            }else if(state == 0) {
                return '草稿'
            }else if(state == 1) {
                return '审核中'
            }else if(state == 2) {
                return '已审核'
            }else if(state == 5) {
                return '已作废'
            }
        },
        //币种切换
        currencyChange (val) {
            this.formData.currency = this.currencyForm.find(
                x => x.value === val
            ).label //币种
            if (this.formData.currency === '人民币') {
                this.formData.rmbRate = 1
            } else {
                getRmbRate({
                    //获取机构下某币种的人民币汇率
                    currency: val,
                    orgId: this.userInfo.orgInfo.orgId
                })
                    .then(res => {
                        console.log(res)
                        this.formData.rmbRate = res.rate
                    })
                    .catch(() => {})
            }
            if (this.formData.currency === this.formData.baseCurName) {
                //币种=本位币
                this.formData.baseCurRate = 1
                this.showBaseCurName = false
            } else {
                this.formData.baseCurRate = null
                this.showBaseCurName = true
            }
        },
        //终期结算
        checkToF () {
            console.log(111)
            if(this.setFinalSettle == true) {
                console.log(this.setFinalSettle)
                this.formData.isFinalSettle == 1
                console.log(this.formData.isFinalSettle)
            }else{
                this.formData.isFinalSettle == 0
            }
        },
        //获取借支人员
        getSigningName ()  {
            selectDataClient({
                SelectServiceToken: '/hr/user/getUserUnderOrgPage', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                InitParamsStr: JSON.stringify({ 'orgId': this.formData.orgId }),    // 接口参数
                Title: '选择借支人员' // 标题
            }).then(val => {
                this.formData.borrower = val[0].userName
            })
        },
        //金额类数据  1、税价合计   2、税额
        taxRateHandel (e) {
            console.log(e)
            if(0 <= e && e < 100) {
                this.formData.taxRate = e + '%'
                // this.formData.taxRate = e
                if(this.formData.taxExcluding && parseInt(this.formData.taxRate)) {
                    this.formData.taxAmount = ( parseInt(this.formData.taxRate) * this.formData.taxExcluding) / 100
                }
            }else{
                this.$message.error('税率填写范围为0~100')
            }
        },
        amountExcludingTaxHandel (e) {
            //不含税金额
            this.formData.taxExcluding = e
            if(this.formData.taxExcluding &&  +this.formData.taxRate) {
                this.formData.taxAmount = ( +this.formData.taxRate * this.formData.taxExcluding) / 100
            }
        },
        contractAmount (e) {
            // 税额
            this.formData.taxAmount = e
            if (this.formData.taxExcluding && this.formData.taxAmount && this.formData.advanceChargeAmount) {
                if(this.formData.advanceChargeAmount == '' || this.formData.advanceChargeAmount == null) {
                    this.formData.totalTaxPrice = Math.ceil9((+this.formData.taxExcluding + +this.formData.taxAmount + +this.formData.advanceChargeAmount) * 100) / 100   //税价合计
                    this.formData.taxAmount = Math.ceil(this.formData.taxAmount * this.formData.taxExcluding) * 100 / 100
                }else{
                    this.formData.totalTaxPrice = Math.ceil((+this.formData.taxExcluding + +this.formData.taxAmount) * 100) / 100   //税价合计
                    this.formData.taxAmount = Math.ceil(this.formData.taxAmount * this.formData.taxExcluding) * 100 / 100
                }
            }
        },
        advanceChargeAmountHandel (e) {
            if(e && e <= this.formData.advanceChargeAmount) {
                this.formData.advanceChargeAmount = e
            }else{
                this.formData.advanceChargeAmount = ''
            }
            //冲预付款金额
            this.formData.advanceChargeAmount = e
            if (this.formData.taxExcluding && this.formData.taxAmount && this.formData.advanceChargeAmount) {
                if(this.formData.advanceChargeAmount != '' || this.formData.advanceChargeAmount != null) {
                    this.formData.totalTaxPrice = Math.ceil((+this.formData.taxExcluding + +this.formData.taxAmount + +this.formData.advanceChargeAmount) * 100) / 100   //税价合计
                }else{
                    this.formData.totalTaxPrice = Math.ceil((+this.formData.taxExcluding + +this.formData.taxAmount) * 100) / 100   //税价合计
                }
            }
        },
        transportUnitCostHandel (e) {
            //服务费用
            this.formData.transportUnitCost = e
            this.formData.cumulativeSettleAmount = Math.ceil((this.formData.totalTaxPrice + +this.formData.transportUnitCost) * 100) / 100
        },
        //
        //冲个人借支金额
        personHandel () {
            // if(e && (e <= this.formData.totalTaxPrice)) {
            //     this.formData.totalTaxPrice = e
            // }else {
            //     this.formData.totalTaxPrice = ''
            // }
            if (this.formData.rushPersonalBorrowingAmount > this.formData.totalTaxPrice || this.formData.rushPersonalBorrowingAmount == '-' || this.formData.rushPersonalBorrowingAmount == '-0') {
                this.clientPop(
                    'err',
                    '冲个人借支金额必须小于等于本次的税价合计并且金额值为正数'
                )
                this.formData.rushPersonalBorrowingAmount = ''
            }
        },
        //冲个人借支
        checkHandel () {
            // if (val) {
            //     this.clientPop(
            //         'info',
            //         '确认冲个人借资？',
            //         () => {},
            //         null,
            //         () => {
            //             this.formData.rushPersonalBorrowing = false
            //         }
            //     )
            // }

            if(this.checkPerson == true) {
                this.checkPerson = false
                console.log(222222)
            }else{
                this.checkPerson = true
                alert('确认冲个人借资？')
            }
        },
        //冲销对象
        async handelChange () {
            alert(this.billid)
            let ids = []
            // let params = []
            // params.push(this.formData.billid)
            selectDataClient({
                SelectServiceToken: '/facilityconnect/lease/receive/plan/contract/receive', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: ids, // 已选中id
                InitParamsStr: JSON.stringify({ 'keyWord': '', 'billId': [ 'this.billid'] }),    // 接口参数(name为模拟参数)
                Title: '选择冲销对象' // 标题
            }).then(val => {
                this.formData.reversalObjectName = val[0].reversalObjectName
                this.formData.reversalObjectId = val[0].leaseUnitId
            })
        },
        checkedHandel () {
            if(this.checked == true) {
                this.message('冲预付款金额为必填项')
            }
        },
        //获取默认数据
        getInInfo () {
            this.formData.writeName = localStorage.getItem('userName')  // 缺少字段
        },
        //点击结算单位按钮
        settleOrgChange () {
            // 弹窗选择数据
            let ids = []
            selectDataClient({
                SelectServiceToken: '/turnover/acceptance/selectSettleDtl', // 获取选择结算明细
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: ids, // 已选中id
                InitParamsStr: JSON.stringify({  'businessTypeKey': '1',
                    'keyWord': '',
                    'parentId': '0' }),
                Title: '选择结算单位数据' // 标题
            }).then(val => {
                this.formData.settleOrg = val[0].settleOrgName
            })
        },
        // 弹窗选择结算编号
        selectPlanNo () {
            if(this.isDisabled) {
                return
            }
            let ids = []
            selectDataClient({
                SelectServiceToken: '/facilityplan/get/configuration/plan', // 客户端对应方法名   待修改数据@@@@@
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: ids, // 已选中id
                Title: '选择结算编号' // 标题
            }).then(val => {
                this.formData.settleNo = val[0].billNo
                this.formData.billId = val[0].billId
            })
        },
        //保存
        preserve () {
            this.$refs.form.validate(valid => {
                if (valid) {
                    request.PccSetNewDataInfo({
                        ...this.formData,
                        businessTypeKey: Number(this.formData.businessTypeKey),
                        taxRate: Number(this.formData.taxRate),
                        checkedBox: this.checkedBox
                    }).then(res=>{
                        this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                            this.$router.push({
                                path: '/NewPlanDetail',
                                query: {
                                    billid: res,
                                    name: 'changeDetail'
                                }
                            })
                        },
                        null,
                        this.handleClose
                        )
                    })
                } else {
                    return false
                }
            })
        },

        //取消
        handleClose () {
            this.$router.replace('/PccSetList')
        },
    },
    watch: {
        //冲红单
        'formData.redStatus' () {
            if (this.formData.redStatus == '3') {
                this.redBillStateStyle.backgroundColor = '#FF2300'
            } else if (
                this.formData.redStatus == '0' ||
                this.formData.redStatus == '1'
            ) {
                this.redBillStateStyle.backgroundColor = '#FFA40D'
            } else if (this.formData.redStatus == '2') {
                this.redBillStateStyle.backgroundColor = 'rgb(153,153,153)'
            }
        },

        // 基础数据累计结算金额(元)的监听
        'formData.cumulativeSettleAmount' () {
            this.formData.cumulativeSettleAmount = this.jiesuanmingxi.children[0].acceptAmount
            // 税价合计 = 累计结算金额 + 税额
            this.formData.totalTaxPrice =
                    +this.formData.cumulativeSettleAmount +
                    +this.fmData.taxAmount
            // 结算金额(本位币) = 结算金额 * 本位币汇率
            this.formData.baseCurAmount =
                +this.formData.cumulativeSettleAmount *
                +this.formData.baseCurRate
        },
        // 监听税额
        'formData.taxAmount' ()  {
            // 税价合计 = 验收金额+税额
            this.formData.totalAmount =
                    +this.formData.cumulativeSettleAmount +
                    +this.formData.taxAmount
        },
        //监听服务服务费用
        'formData.transportUnitCost' ()  {
            // 服务税价合计 = 金额 + 税额
            this.formData.transportUnitCost = this.serviceFeeRow.taxAmount +
                    +this.serviceFeeRow.amount
        },
        //监听服务服务费用税额
        'serviceFeeRow.totalAmountt' () {
            // 服务税额 = 金额 * 税率
            this.serviceFeeRow.totalAmount =
                    +this.serviceFeeRow.amount *
                    +this.serviceFeeRow.taxRate
        },
        /* //监听业务类型变化
        'formData.taxRate' (contractId) {
            if (this.formData.businessTypeKey == 2) {
                this.$Ajax.httpGet({
                    url: '/subcontract/thirdParty/getMaterialProcurementInfo',
                    params: {
                        contractId
                    }
                }).then(res =>{
                    let data1  = res
                    console.log(data1)
                    if (data1) {
                        this.formData.currency = data1.currencyName // 币种名称
                        this.formData.currencyId = data1.currencyId // 币种ID
                        this.formData.baseCurName = data1.baseCurName // 本位币名称
                        this.formData.baseCurId = data1.baseCurId // 本位币ID
                        this.formData.taxRate = data1.taxRate // 物资采购合同：带入合同税率。
                    }
                })
            }
        } */
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
